package com.key.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.key.modules.dto.CarrierStDTO;
import com.key.modules.entity.Carrier;
import com.key.modules.entity.CarrierSt;
import com.key.modules.mapper.CarrierMapper;
import com.key.modules.mapper.CarrierStMapper;
import com.key.modules.service.CarrierStService;
import com.key.modules.vo.CarrierPayVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class CarrierStServiceImpl implements CarrierStService {
    @Autowired
    CarrierStMapper carrierStMapper;

    @Override
    public Map<String, Object> findCarrierStatement(CarrierStDTO carrierStDTO) {
        log.info("进入findCustomerReceivable方法，查找信息（支持高级搜索）"+
                "，CurrentPage = "+carrierStDTO.getCurrentPage()+
                "，pageSize = "+carrierStDTO.getPageSize()+
                "，StatementNumber = "+carrierStDTO.getStatementNumber()+
                "，CreationTime = "+carrierStDTO.getCreationTime()+
                "，BillingStatus= "+carrierStDTO.getBillingStatus()

        );
        //设置paage分页查询
        Page<CarrierSt> page=new Page<>(carrierStDTO.getCurrentPage(),carrierStDTO.getPageSize());
        LambdaQueryWrapper<CarrierSt> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(StringUtils.isNotEmpty(carrierStDTO.getStatementNumber()), CarrierSt::getStatementNumber, carrierStDTO.getStatementNumber())
                .eq(StringUtils.isNotEmpty(carrierStDTO.getCreationTime()), CarrierSt::getCreationTime, carrierStDTO.getCreationTime())
                .eq(carrierStDTO.getBillingStatus()!=null, CarrierSt::getBillingStatus, carrierStDTO.getBillingStatus());

        Page<CarrierSt> reVOPage= carrierStMapper.selectPage(page,lambdaQueryWrapper);
        //将获取的page里的total与数据返回
        List<CarrierSt> voList=reVOPage.getRecords();
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("data",voList);
        Integer total=(int)page.getTotal();
        resultMap.put("total",total);

        log.info("findCarrierPayable方法结束返回数据");
        return resultMap;
    }

    @Override
    public int deleteStatement(String no) {
        QueryWrapper<CarrierSt> lambdaQueryWrapper=new QueryWrapper<>();
        lambdaQueryWrapper.eq("statement_number",no);
        int i=carrierStMapper.delete(lambdaQueryWrapper);
        return i;
    }

    @Override
    public int editStatement(CarrierSt carrierSt) {
        QueryWrapper<CarrierSt> queryWrapper=new QueryWrapper();
        queryWrapper.eq("statement_number",carrierSt.getStatementNumber());
        int i=carrierStMapper.update(carrierSt,queryWrapper);
        return i;
    }
}
